<?php

class Jenis_simp_model extends Model {
	
	var $data;

	function Jenis_simp_model()
	{
		parent::Model();
	}
	
	function get_all_data(){
		$query = $this->db->get('jenis_simp');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_jum_data(){
		$query = $this->db->query('select count(*) as jumlah from jenis_simp');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_last_id(){
		$query = $this->db->query('select * from jenis_simp order by id_jenis_simp desc limit 1 ');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}

	function get_data_by_id($id){
		$this->db->where('id', $id);
		$query = $this->db->get('jenis_simp');
		if ($query->num_rows() > 0)
		{
			return $query->row_array();
		}
		else
		{
			return FALSE;
		}
	}

	function fill_data()
	{
		$this->data = array(
			'id_jenis_simp' => $this->input->post('id_jenis_simp'),			
			'bunga' => $this->input->post('bunga'),
			'jumlah' => $this->input->post('jumlah')
		);
	}
	
	//Check for duplicate ID jenis_simp
	function check_name($id = '')
	{
		$this->db->where('id_jenis_simp', $this->data['id_jenis_simp']);
		if($id != '') $this->db->where('id !=', $id);
		$query = $this->db->get('jenis_simp');

		if ($query->num_rows() > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}	

	function insert_data()
	{
		$insert = $this->db->insert('jenis_simp', $this->data);
		return $insert;
	}

	function update_data($id)
	{
		$this->db->where('id', $id);
		$update = $this->db->update('jenis_simp', $this->data);
		return $update;
	}

	function delete_data($id){
		$this->db->where('id', $id);
		$delete = $this->db->delete('jenis_simp');
		return $delete;
	}

}

/* End of file jenis_simp_model.php */
/* Location: ./application/models/jenis_simp_model.php */
